package com.ruoyi.teacher.service.impl;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.teacher.domain.Review;
import com.ruoyi.teacher.mapper.ReviewRepository;
import com.ruoyi.teacher.service.ReviewSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ReviewServiceImpl implements ReviewSevice {


    @Autowired
    private ReviewRepository reviewRepository;

    @Override
    public List<Review> getList() {
        return reviewRepository.findAll();
    }

    @Override
    public TableDataInfo getPage(int num, int size) {
        PageRequest of = PageRequest.of(num, size);
        List<Review> all = reviewRepository.findAll();
//        Page<Review> all = reviewRepository.findAll(of);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(all);
        return tableDataInfo;
    }

    @Override
    public void getAdd(Review review) {
        Review save = reviewRepository.save(review);

        reviewRepository.deleteById(save.getId());
    }
}
